package com.ruoyi.kesheSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.kesheSys.domain.vo.PopulationRegionVo;
import com.ruoyi.kesheSys.to.BusinessTo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kesheSys.domain.PopulationRegion;
import com.ruoyi.kesheSys.service.IPopulationRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人口区域信息Controller
 * 
 * @author keshe
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/kesheSys/region")
public class PopulationRegionController extends BaseController
{
    @Autowired
    private IPopulationRegionService populationRegionService;

    /**
     * 查询人口区域信息列表
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(PopulationRegion populationRegion)
    {
        startPage();
        List<PopulationRegionVo> list = populationRegionService.selectPopulationRegionListVo(populationRegion);
        return getDataTable(list);
    }

    /**
     * 导出人口区域信息列表
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:export')")
    @Log(title = "人口区域信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PopulationRegion populationRegion)
    {
        List<PopulationRegion> list = populationRegionService.selectPopulationRegionList(populationRegion);
        ExcelUtil<PopulationRegion> util = new ExcelUtil<PopulationRegion>(PopulationRegion.class);
        util.exportExcel(response, list, "人口区域信息数据");
    }

    /**
     * 获取人口区域信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId)
    {
        return success(populationRegionService.selectPopulationRegionByRegionId(regionId));
    }

    /**
     * 新增人口区域信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:add')")
    @Log(title = "人口区域信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PopulationRegion populationRegion)
    {
        return toAjax(populationRegionService.insertPopulationRegion(populationRegion));
    }

    /**
     * 修改人口区域信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:edit')")
    @Log(title = "人口区域信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PopulationRegion populationRegion)
    {
        return toAjax(populationRegionService.updatePopulationRegion(populationRegion));
    }

    /**
     * 删除人口区域信息
     */
    @PreAuthorize("@ss.hasPermi('kesheSys:region:remove')")
    @Log(title = "人口区域信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds)
    {
        return toAjax(populationRegionService.deletePopulationRegionByRegionIds(regionIds));
    }

    /**
     * 查询各区域人口比重

    @GetMapping("/statistics/percentage")
    public AjaxResult getPopulationPercentageByRegion() {
        List<BusinessTo> result = populationRegionService.selectPopulationPercentageByRegion();
        return AjaxResult.success(result);
    }
*/

}
